package main

import (
	"fmt"
	"math/rand"
	"time"
)


func RandInt(max int) int {
	if max <= 1 {
		return 1
	}
	rr := rand.New(rand.NewSource(time.Now().UnixNano() * rand.Int63n(9999)))
	return rr.Intn(max) + 1
}

type DealMachine struct {
	cards []int
}

func (dm *DealMachine)Shuffle()  {

	total := len(dm.cards)
	for k := 0; k < 5; k++ {
		source := rand.NewSource(time.Now().UnixNano() + int64(RandInt(10000)))
		r := rand.New(source)
		randomIndex := r.Perm(total)
		fmt.Println(total, randomIndex)
		for i := 0; i < total; i++ {
			dm.swapCard(i, randomIndex[i])
		}
	}


}

func (dm *DealMachine)swapCard(a int, b int) {
	tmp := dm.cards[a]
	dm.cards[a] = dm.cards[b]
	dm.cards[b] = tmp
}


func (this *DealMachine) Shuffle2() []int {
	nums := make([]int, len(this.cards))
	buf := make([]int, len(this.cards))
	copy(buf, this.cards)
	for i := range nums {
		j := rand.Intn(len(buf))
		nums[i] = buf[j]
		buf = append(buf[0:j], buf[j+1:]...)
	}
	return nums
}


func main(){
	dm := new(DealMachine)
	dm.cards = make([]int, 52, 52)
	for i := 0; i < 4; i++ {
		for j := 0; j < 13; j++ {
			dm.cards[i*13+j] = j + 1
			fmt.Printf("%d ", i*13+j)
		}
		fmt.Println()
	}
	dm.Shuffle()
	//fmt.Printf("cards:%v ", dm.cards)
	for i := 0; i < 4; i++ {
		for j := 0; j < 13; j++ {
			fmt.Printf("%d ", dm.cards[i*13+j])
		}
		fmt.Println()
	}
	//dm.Shuffle2()

	mp := map[int]string{
		1:"sss",
	}
	fmt.Println(mp)

}